﻿using KinectWindowLib.Graphics;
using KinectWindows.Math;
using KinectWindows.Windows;
using SharpGL;
using SharpGL.SceneGraph;
using SharpGL.SceneGraph.Cameras;
using SharpGL.SceneGraph.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KinectWindowLib
{
    /// <summary>
    /// The Screen Object all Screen must Drive from this class
    /// </summary>
    public class Screen
    {
        public long Id { get; set; }
        private GraphicContext gc;
        public void SetBounds(Double Width, Double Height)
        {
            this.Width = Width;
            this.Height = Height;
        }
        public Scene GL_Scene { set; get; }
        public Screen(OpenGL gl)
        {
           // CreateGLScene();
            gc = new GraphicContext();
            gc.CreateGC(gl);
        }
        public void Refresh()
        {
            GL_Scene.OpenGL.ClearColor(0, 0, 0, 0);
            GL_Scene.Draw();
        }
        private void CreateGLScene()
        {
            GL_Scene = new Scene();
            //  Create the 'Look At' camera
            var lookAtCamera = new LookAtCamera()
            {
                Position = new Vertex(0f, 5f, 0f),
                Target = new Vertex(0f, 0f, 0f),
                UpVector = new Vertex(0f, 0f, 1f)
            };

            //  Set the look at camera as the current camera.
            GL_Scene.CurrentCamera = lookAtCamera;



            //  Create a set of scene attributes.
            OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect()
            {
                Name = "Scene Attributes"
            };

            //  Specify the scene attributes.
            sceneAttributes.EnableAttributes.EnableDepthTest = true;
            sceneAttributes.EnableAttributes.EnableNormalize = true;
            sceneAttributes.EnableAttributes.EnableLighting = true;
            sceneAttributes.EnableAttributes.EnableTexture2D = true;
            sceneAttributes.EnableAttributes.EnableBlend = true;
            // sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha;
            // sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha;
            sceneAttributes.LightingAttributes.TwoSided = true;




        }
        public double Width { get; set; }
        public double Height { get; set; }

        public Graphics.GraphicContext GC { get { return gc; } }

        internal void Clear()
        {
            GL_Scene.OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gc.ClearGC();
        }
    }
}
